#include <bits/stdc++.h>
using namespace std;
bool isdig(char c){return '0' <=c && c <= '9';} 
const int N = 2e5 + 5;
const int M = 5005;
typedef long long ll; 
ll read(){
    ll x = 0 , f = 1;
    char c = getchar();
    while (!isdig(c)){
        if (c == '-') f = -1;
        c = getchar();
    }
    while (isdig(c)){
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    return x * f;
}
void write(ll x){
    if (x < 0){
        x = -x;
        putchar('-');
    }
    if (x >= 10) write(x / 10);
    putchar(x % 10 + '0');
}
ll a[N],dp[N][5];
ll connect[N];
ll work(ll l ,ll r){
    return connect[r] - connect[l];
}
void solve1(ll n){
    for (int i = 1 ; i <= n ; i ++){
        if (a[i] == a[i - 1]) connect[i] = connect[i - 1] + a[i];
        else connect[i] = connect[i - 1];
    }
    for (int i = 1 ; i <= n ;i ++){
        dp[i][0] = dp[i][1] = 0ll;
        for (int j = 1 ; j < i ; j ++){
            dp[i][0]=max(dp[i][0],max(dp[j][0]+work(j,i-1)+(a[i]==a[j])*a[i] , dp[j][1]+work(j+1,i-1)+(a[i]==a[j-1])*a[i]));
            dp[i][1]=max(dp[i][1],max(dp[j][1]+work(j,i-1)+(a[i]==a[j])*a[i] , dp[j][0]+work(j+1,i-1)+(a[i]==a[j-1])*a[i]));
        }
        cout << dp[i][0] << " " << dp[i][1] << endl;
    }
    write(max(dp[n][0] , dp[n][1]));
    putchar('\n');
}
vector <int> col[3];
void solve2(ll n){
    ll sum = 0 , ans = 0;
    for (int i = 0 ; i <= (1 << n) - 1 ; i ++){
        sum = 0;
        col[0].clear();
        col[1].clear();
        for (int j = 1 ; j <= n ; j ++){
            if (i & (1 << (j - 1))) col[1].push_back(j);
            else col[0].push_back(j);
        }
        for (int k = 0 ; k <= 1 ; k ++)
        for (int j = 1; j < col[k].size() ; j ++){
            sum += (a[col[k][j]] == a[col[k][j - 1]]) * a[col[k][j]];
        }
        if (sum > ans){
            // for (int k = 0 ; k <= 1 ; k ++){
            //     for (int j = 0; j < col[k].size() ; j ++){
            //         cout << a[col[k][j]] << " ";
            //     }
            //     cout << endl;
            // }
            // cout << i << "c" << sum << endl;
        }
        ans = max(ans , sum);
    }
    write(ans);
    putchar('\n');
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out" , "w",stdout);
    ll T = read();
    while (T --){
        ll n = read();
        for (int i = 1 ; i <= n ; i ++) a[i] = read();
        if (n <= 20) solve2(n);
        else cout << 0 << endl;
    }
    return 0;
}